package com.coin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coin.domain.AdminAddress;
import com.coin.model.R;
import com.coin.service.AdminAddressService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Auther: 李 力
 * @Date: 2025/6/12
 * @Description: com.coin.controller
 * @version: 1.0
 */
@Api(tags = "归集地址的控制器")
@RestController
@RequestMapping("/adminAddress")
public class AdminAddressController {


    @Autowired
    private AdminAddressService adminAddressService;


    /**
     * @Description: 查询归集地址
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @GetMapping
    @ApiOperation(value = "查询归集地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinId", value = "币种的id"),
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数"),
    })
    public R<Page<AdminAddress>> findByPage(@ApiIgnore Page<AdminAddress> page, Long coinId) {
        Page<AdminAddress> adminAddressPage = adminAddressService.findByPage(page, coinId);
        return R.ok(adminAddressPage);
    }

    /**
     * @Description: 归集地址的新增
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @PostMapping
    @ApiOperation(value = "归集地址的新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminAddress", value = "adminAddress json")
    })
    public R save(@RequestBody @Validated AdminAddress adminAddress) {
        boolean save = adminAddressService.saveAdminAddress(adminAddress);
        return save ? R.ok() : R.fail("新增失败");
    }

    /**
     * @Description: 归集地址的修改
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @PutMapping
    @ApiOperation(value = "归集地址的修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminAddress", value = "adminAddress json")
    })
    public R update(@RequestBody @Validated AdminAddress adminAddress) {
        boolean isOk = adminAddressService.updateAdminAddress(adminAddress);
        return isOk ? R.ok() : R.fail("修改失败");
    }
}
